package cz.muni.fi.pa165.sme.services;

import cz.muni.fi.pa165.sme.dao.exception.DataStorageOperationException;
import cz.muni.fi.pa165.sme.dao.exception.ReferenceIntegrityException;
import cz.muni.fi.pa165.sme.exceptions.ServiceException;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author jirankova
 */
@Component
@Order(1500)
@Aspect
public class ExceptionConversionAspect {

	@AfterThrowing(throwing = "e", pointcut = "execution(* cz.muni.fi.pa165.sme.services.impl.*.*(..))")
	public void convertDataStorageOperationException(Throwable e) {
		if(e instanceof DataStorageOperationException || e instanceof ReferenceIntegrityException) {
			throw new ServiceException(e.getMessage(), e);
		}
	}
}
